package mhl.service;

import mhl.dao.BillDao;
import mhl.domain.Bill;


import java.util.List;
import java.util.UUID;

public class Billservice {
    BillDao billDao=new BillDao();
    MenuService menuService=new MenuService();
    DiningTbale diningTbale=new DiningTbale();

    public boolean orderBill(int menuId,int nums,int diningTableId){
        String billId= UUID.randomUUID().toString();
        int update=billDao.update("insert into bill values(null,?,?,?,?,?,now(),'未结账')",
                billId,menuId,nums,menuService.getmenuId(menuId).getMenuPrice()*nums,diningTableId);
        if(update<=0){
            return false;
        }
        return diningTbale.updateTableState(diningTableId,"就餐中");
    }
    public List<Bill> getBillTable(){
        return billDao.querymulti("select * from bill", Bill.class);
    }
    public boolean haspaybill(int diningTableId){
        Bill bill=billDao.querysingle("select * from bill where diningTableId=? and State='未结账' Limit 0,1",Bill.class,diningTableId);
        return bill!=null;
    }
    public boolean paybill(int diningTableId,String Paymode){
        int update=billDao.update("update bill set bState=? where diningTableId=? and State='未结账'",Paymode,diningTableId);
        if (update<=0){
            return false;
        }
         if (diningTbale.updateTableFree(diningTableId,"空")){
             return false;
         }
         return true;
    }

}
